package leetcode

func twoSum(nums []int, target int) []int {
	numMap := make(map[int]int)
	var res []int
	for idx, item := range nums {
		numMap[item] = idx
	}

	for idx, item := range nums {
		another := target - item
		if anotherIdx, ok := numMap[another]; ok && anotherIdx != idx {
			res = append(res, idx, anotherIdx)
			break
		}
	}
	return res
}
